<?php

require_once "ZendX/JQuery.php";

class ZT_CodaSlider extends Zend_View_Helper_HtmlElement {

  protected $_panes = array();
  protected $jquery;

  /**
   * Set view and enable jQuery Core and UI libraries
   *
   * @param  Zend_View_Interface $view
   * @return ZT_CodaSlider
   */
  public function setView(Zend_View_Interface $view) {
    parent::setView($view);
    $this->jquery = $this->view->jQuery();
    $this->jquery->enable()
            ->uiEnable();
    $view->jQuery()->enable();
    return $this;
  }

  /**
   * jQuery-enable a view instance
   *
   * @param  Zend_View_Interface $view
   * @return void
   */
  public static function enableView(Zend_View_Interface $view) {
    if (false === $view->getPluginLoader('helper')->getPaths('ZT_CodaSlider')) {
      $view->addHelperPath('ZT/CodaSlider', 'ZT_CodaSlider');
      ZendX_JQuery::enableView($view);
    }
  }

  /**
   * Encode Json that may include javascript expressions.
   *
   * Take care of using the Zend_Json_Encoder to alleviate problems with the json_encode
   * magic key mechanism as of now.
   *
   * @see Zend_Json::encode
   * @param  mixed $value
   * @return mixed
   */
  public static function encodeJson($value) {
    if (is_array($value) && count($value) == 0) {
      return '{}';
    }
    if (!class_exists('Zend_Json')) {
      /**
       * @see Zend_Json
       */
      require_once "Zend/Json.php";
    }
    return Zend_Json::encode($value, false, array('enableJsonExprFinder' => true));
  }

}